<template>
	<view class='login'>
		<view class="bg">
			<image src="../../static/img/bg_Headportrait@1x.png" />
		</view>
		<view class="content">
			<view class="main">
				<view class="logo">
					<image src="../../static/img/logo.png" style="width: 208rpx; height: 208rpx;" />
				</view>
				<view class="form">
					<wd-form ref="form" :model="model">
						<wd-cell-group border>
							<view class="imput">
								<image src="../../static/img/btn_number@2x.png"></image>
								<wd-input :no-border="true" :maxlength="11" prop="mobile" clearable
									v-model="model.mobile" placeholder="请输入账号"
									:rules="[{ required: true, message: '请输入账号', }]">
								</wd-input>
							</view>
							<view class="imput">
								<image src="../../static/img/btn_Password@2x.png"></image>
								<wd-input :no-border="true" prop="password" show-password clearable
									v-model="model.password" placeholder="请输入密码"
									:rules="[{ required: true, message: '请输入密码', }]" />
							</view>
						</wd-cell-group>
					</wd-form>
					<view class="zh">
						<view @click="jump(listUrl[0])">申请加盟</view>
						<view @click="jump(listUrl[1])">找回密码</view>
					</view>
				</view>
				<view class="footer">
					<wd-button type="primary" size="large" @click="handleSubmit" block>登录</wd-button>
				</view>
			</view>
		</view>
	</view>
</template>
<script setup name='login'>
import { login } from '../../request/api/home.js'
import { ref, reactive } from 'vue'
import { onShow, onHide } from '@dcloudio/uni-app'


onShow(() => {
	if (uni.getStorageSync('token')) {
		uni.switchTab({
			url: '/pages/home/home'
		})
	}
})

const model = reactive({
	mobile: '',
	password: '',
	openId: 'openId',
})
const form = ref()
const handleSubmit = function () {
	form.value
		.validate()
		.then(({ valid, errors }) => {
			if (valid) {
				login(model).then((res) => {
					if (res.code == 0) {
						uni.setStorageSync('token', res.data.token)
						uni.showToast({
							title: '登录成功',
							icon: 'none'
						})
						let time = setTimeout(() => {
							clearTimeout(time)
							uni.switchTab({
								url: '/pages/home/home'
							})
						}, 1000);
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}
		})
		.catch((error) => {
		})
}
const listUrl = ref([{
	url: "/subpackageA/applyToJoin/applyToJoin"
}, {
	url: "/subpackageA/retrievePassword/retrievePassword"
}])
const jump = function ({ url }) {
	uni.navigateTo({
		url
	})
}
</script>
<style lang='scss' scoped>
.login {
	height: 100%;
	position: relative;

	.bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.content {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		box-sizing: border-box;


		.main {
			.logo {
				padding: 142rpx 0 80rpx;
				box-sizing: border-box;
				display: grid;
				place-content: center;

				image {
					width: 238rpx;
					height: 238rpx;
				}
			}

			.form {
				padding: 56rpx 50rpx;
				box-sizing: border-box;
				border-radius: 16rpx;
				background: #fff;
				margin: 0 58rpx;
				box-shadow: 0rpx 12rpx 28rpx -4rpx rgba(0, 0, 0, 0.1), 0rpx -12rpx 18rpx -14rpx rgba(0, 0, 0, 0.1);

				.imput {
					border-bottom: 2rpx solid #44ABEF;
					padding: 10rpx 30rpx;
					margin-bottom: 16rpx;
					display: flex;
					align-items: center;

					image {
						width: 45rpx;
						height: 45rpx;
						margin-right: 20rpx;
					}
				}


				.zh {
					padding: 40rpx;
					box-sizing: border-box;
					display: flex;
					justify-content: space-evenly;
				}
			}

			.footer {
				margin: 60rpx 64rpx;
			}

		}
	}
}
</style>